Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / androidApp / src / google / kotlin / org / meshtastic / app / map / tiles / RasterTileProvider.kt

Displaying Raw • Download

androidApp/src/google/kotlin/org/meshtastic/app/map/tiles/RasterTileProvider.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 3.03 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.map.tiles

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787com.google.android.gms.maps.model.Tile
Tff7b72import T7ee787com.google.android.gms.maps.model.TileProvider
Tff7b72import T7ee787okhttp3.OkHttpClient
Tff7b72import T7ee787okhttp3.Request
Tff7b72import T7ee787org.meshtastic.feature.map.tiles.RasterTileSpec
Tff7b72import T7ee787org.meshtastic.feature.map.tiles.tileUrl
Tff7b72import T7ee787java.io.IOException

Tff7b72private Tff7b72val Te6edf3logger Tff7b72= Te6edf3LoggerTb4b4b4.Te6edf3withTagTb4b4b4(Ta5d6ff"Ta5d6ffRasterTileProviderTa5d6ff"Tb4b4b4)

T8b949e/**
* Draws a [RasterTileSpec] on the Google map, fetching its tiles through a caching HTTP client.
*
* Google's own `UrlTileProvider` opens a bare stream per tile and keeps nothing, so panning re-downloads tiles that
* were on screen a moment ago and the map blanks out behind the requests (#2714). Going through OkHttp gives the tiles
* a disk cache that honours what the tile server says about caching, which is what the MapLibre map gets from its
* renderer for free.
*/
Tff7b72class T56d364RasterTileProviderTb4b4b4(Tff7b72private Tff7b72val Te6edf3specTb4b4b4: Te6edf3RasterTileSpecTb4b4b4, Tff7b72private Tff7b72val Te6edf3clientTb4b4b4: Te6edf3OkHttpClientTb4b4b4) Tb4b4b4: Te6edf3TileProvider Tb4b4b4{

Tff7b72override Tff7b72fun Td2a8ffgetTileTb4b4b4(Te6edf3xTb4b4b4: Tffa657IntTb4b4b4, Te6edf3yTb4b4b4: Tffa657IntTb4b4b4, Te6edf3zoomTb4b4b4: Tffa657IntTb4b4b4)Tb4b4b4: Te6edf3Tile? Tb4b4b4{
T8b949e// NO_TILE means "there is definitively nothing here" and is cached as such; a zoom outside the source's range
T8b949e// is exactly that, whereas a failed fetch below is not and must stay retryable.
Tff7b72val Te6edf3url Tff7b72= Te6edf3specTb4b4b4.Te6edf3tileUrlTb4b4b4(Te6edf3xTb4b4b4, Te6edf3yTb4b4b4, Te6edf3zoomTb4b4b4) Tff7b72?: Tff7b72return Te6edf3TileProviderTb4b4b4.Te6edf3NO_TILE
Tff7b72return Te6edf3fetchTb4b4b4(Te6edf3urlTb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72fun Td2a8fffetchTb4b4b4(Te6edf3urlTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3Tile? Tff7b72= Tff7b72try Tb4b4b4{
Te6edf3clientTb4b4b4.Te6edf3newCallTb4b4b4(Te6edf3RequestTb4b4b4.Te6edf3BuilderTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3urlTb4b4b4(Te6edf3urlTb4b4b4)Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3executeTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3use Tb4b4b4{ Te6edf3response Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3responseTb4b4b4.Te6edf3isSuccessfulTb4b4b4) Tb4b4b4{
Te6edf3responseTb4b4b4.Te6edf3bodyTb4b4b4.Te6edf3bytesTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3takeIf Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3isNotEmptyTb4b4b4(Tb4b4b4) Tb4b4b4}Tff7b72?.Te6edf3let Tb4b4b4{ Te6edf3TileTb4b4b4(Te6edf3specTb4b4b4.Te6edf3tileSizeTb4b4b4, Te6edf3specTb4b4b4.Te6edf3tileSizeTb4b4b4, Tffa657itTb4b4b4) Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3loggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ffTile server answered Tffd700${Te6edf3responseTb4b4b4.Te6edf3codeTffd700}Ta5d6ff" Tb4b4b4}
Tff7b72null
Tb4b4b4}
Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IOExceptionTb4b4b4) Tb4b4b4{
T8b949e// Offline, or the tile host is down. Null rather than NO_TILE, so the map asks again.
Te6edf3loggerTb4b4b4.Te6edf3dTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffTile fetch failedTa5d6ff" Tb4b4b4}
Tff7b72null
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IllegalArgumentExceptionTb4b4b4) Tb4b4b4{
T8b949e// OkHttp rejected the URL the template produced. The template is the user's, so this is not ours to crash
T8b949e// on — but it will not fix itself either, so refuse the tile rather than retrying forever.
Te6edf3loggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffTile url rejectedTa5d6ff" Tb4b4b4}
Te6edf3TileProviderTb4b4b4.Te6edf3NO_TILE
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.06s